package com.rzdata.poct.web.controller.business;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rzdata.poct.common.core.page.TableDataInfo;
import com.rzdata.poct.system.domain.business.bo.PoctInstrumentComparisonBo;
import com.rzdata.poct.system.domain.business.po.PoctInstrumentComparison;
import com.rzdata.poct.system.domain.business.vo.PoctInstrumentComparisonVo;
import com.rzdata.poct.system.service.IPoctInstrumentComparisonService;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.rzdata.poct.common.annotation.RepeatSubmit;
import com.rzdata.poct.common.annotation.Log;
import com.rzdata.poct.common.core.controller.BaseController;
import com.rzdata.poct.common.core.domain.AjaxResult;
import com.rzdata.poct.common.core.validate.AddGroup;
import com.rzdata.poct.common.core.validate.EditGroup;
import com.rzdata.poct.common.core.validate.QueryGroup;
import com.rzdata.poct.common.enums.BusinessType;
import com.rzdata.poct.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.Arrays;
import java.util.List;

/**
 * 设备一致性比对Controller
 *
 * @author ruoyi
 * @date 2021-09-17
 */
@Validated
@Api(value = "设备一致性比对控制器", tags = {"设备一致性比对管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/instrumentComparison")
public class PoctInstrumentComparisonController extends BaseController {

    private final IPoctInstrumentComparisonService iPoctInstrumentComparisonService;

    /**
     * 查询设备一致性比对列表
     */
    @ApiOperation("查询设备一致性比对列表")
    @PreAuthorize("@ss.hasPermi('system:instrumentComparison:list')")
    @PostMapping("/list")
    public TableDataInfo<PoctInstrumentComparisonVo> list(@RequestBody PoctInstrumentComparisonBo bo) {
        return iPoctInstrumentComparisonService.queryPageList(bo);
    }

    @ApiOperation("查询设备一致性比对列表")
    @PreAuthorize("@ss.hasPermi('system:instrumentComparison:list')")
    @PostMapping("/queryPage")
    public IPage<PoctInstrumentComparisonVo> queryPage(@RequestBody PoctInstrumentComparisonBo bo) {
        return iPoctInstrumentComparisonService.queryPage(bo);
    }

    /**
     * 导出设备一致性比对列表
     */
    @ApiOperation("导出设备一致性比对列表")
    @PreAuthorize("@ss.hasPermi('system:instrumentComparison:export')")
    @Log(title = "设备一致性比对", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated PoctInstrumentComparisonBo bo, HttpServletResponse response) {
        List<PoctInstrumentComparisonVo> list = iPoctInstrumentComparisonService.queryList(bo);
        ExcelUtil.exportExcel(list, "设备一致性比对", PoctInstrumentComparisonVo.class, response);
    }

    /**
     * 获取设备一致性比对详细信息
     */
    @ApiOperation("获取设备一致性比对详细信息")
    @PreAuthorize("@ss.hasPermi('system:instrumentComparison:query')")
    @GetMapping("/{id}")
    public AjaxResult<PoctInstrumentComparisonVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iPoctInstrumentComparisonService.queryById(id));
    }

    /**
     * 新增设备一致性比对
     */
    @ApiOperation("新增设备一致性比对")
    @PreAuthorize("@ss.hasPermi('system:instrumentComparison:add')")
    @Log(title = "设备一致性比对", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody PoctInstrumentComparisonBo bo) {
        return toAjax(iPoctInstrumentComparisonService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改设备一致性比对
     */
    @ApiOperation("修改设备一致性比对")
    @PreAuthorize("@ss.hasPermi('system:instrumentComparison:edit')")
    @Log(title = "设备一致性比对", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody PoctInstrumentComparisonBo bo) {
        return toAjax(iPoctInstrumentComparisonService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除设备一致性比对
     */
    @ApiOperation("删除设备一致性比对")
    @PreAuthorize("@ss.hasPermi('system:instrumentComparison:remove')")
    @Log(title = "设备一致性比对" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iPoctInstrumentComparisonService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    /**
     * 删除设备一致性比对
     */
    @ApiOperation("删除设备一致性比对")
    @PreAuthorize("@ss.hasPermi('system:instrumentComparison:remove')")
    @Log(title = "设备一致性比对" , businessType = BusinessType.DELETE)
    @GetMapping("/cancelById/{id}")
    public AjaxResult<Void> cancelById(@PathVariable("id")Long id) {
        return toAjax(iPoctInstrumentComparisonService.cancelById(id) ? 1 : 0);
    }
}
